<%
	def tableDefine=tableModel.tableDefine;
	def columns=tableDefine.columns;
	def tableNameLowerCaseFirst=tableNameUtil.lowerCaseFirst(tableDefine.id);
	def pkColumn=tableDefine.getPkColumn();
    def pkJavaType=tableNameUtil.getDataType(pkColumn?.columnType);
%>package ${config.basePackage}${PubUtils.addStrAfterSeparator(config.category,".")}.controller;

import com.znv.common.base.ZnvPage;
import com.znv.common.base.ZnvResult;
import com.znv.common.utils.Constant;
import ${config.basePackage}${PubUtils.addStrAfterSeparator(config.category,".")}.dto.${tableDefine.id}AddDTO;
import ${config.basePackage}${PubUtils.addStrAfterSeparator(config.category,".")}.dto.${tableDefine.id}UpdateDTO;
import ${config.basePackage}${PubUtils.addStrAfterSeparator(config.category,".")}.dto.${tableDefine.id}ViewDTO;
import ${config.basePackage}${PubUtils.addStrAfterSeparator(config.category,".")}.entity.${tableDefine.id}Entity;
import ${config.basePackage}${PubUtils.addStrAfterSeparator(config.category,".")}.service.${tableDefine.id}Service;
import com.znv.logservice.api.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;



/**
 * ${tableDefine.cnname} controller
 *
 * @author ${config.author}
 * @date ${config.nowDate}
 */
@Api("${tableDefine.cnname}相关接口")
@RestController
@RequestMapping("${PubUtils.addStrAfterSeparator(PubUtils.packageToPath(config.category),"/")}/${tableNameLowerCaseFirst}")
public class ${tableDefine.id}Controller {
    
	@Autowired
    private ${tableDefine.id}Service ${tableNameLowerCaseFirst}Service;

    @GetMapping
    @ApiOperation(value = "${tableDefine.cnname}-分页查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="int") ,
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
            @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,""
            @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType="String") ,
<%
			columns.each{
				if(it==null || tableModel.isNotInList('searchKey',it.columnName)){
					return ;
				}
				println """	@ApiImplicitParam(name = "${it.dataName}", value = "${it.cnname}", paramType = "query", dataType="${tableNameUtil.getDataType(it.columnType)}") ,""";
}%>
	})
    public ZnvResult<ZnvPage<${tableDefine.id}Entity>> list(@ApiIgnore @RequestParam Map<String, Object> params){
        ZnvPage<${tableDefine.id}Entity> page = ${tableNameLowerCaseFirst}Service.znvPage(params);

        return new ZnvResult<ZnvPage<${tableDefine.id}Entity>>().ok(page);
    }


    @GetMapping("{${pkColumn.dataName}}")
    @ApiOperation(value = "${tableDefine.cnname}-详情接口")
    public ZnvResult<${tableDefine.id}ViewDTO> info(@PathVariable("${pkColumn.dataName}") ${pkJavaType} ${pkColumn.dataName}){
		${tableDefine.id}ViewDTO dto = eventInfoService.iGetById(${pkColumn.dataName});

        return new ZnvResult<${tableDefine.id}ViewDTO>().ok(dto);
    }

    @PostMapping
	@SysLog("${tableDefine.cnname}-新增")
    @ApiOperation(value = "${tableDefine.cnname}-新增接口")
    public ZnvResult save(@RequestBody ${tableDefine.id}AddDTO dto){
        ${tableNameLowerCaseFirst}Service.iSave(dto);

        return new ZnvResult();
    }

	@PutMapping
	@SysLog("${tableDefine.cnname}-更新")
    @ApiOperation(value = "${tableDefine.cnname}-更新接口")
    public ZnvResult update(@RequestBody ${tableDefine.id}UpdateDTO dto){
        ${tableNameLowerCaseFirst}Service.iUpdate(dto);

        return new ZnvResult();
    }
	
    @DeleteMapping
	@SysLog("${tableDefine.cnname}-删除")
	@ApiOperation(value = "${tableDefine.cnname}-删除接口")
    public ZnvResult delete(@RequestBody ${pkJavaType}[] ids){
        eventInfoService.iDelete(ids);

        return new ZnvResult();
    }
}